package br.ita.supertrunfo.server.domain;

import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;

import br.ita.supertrunfo.server.domain.CartaIP;

public class BaralhoIP implements Serializable {

	private static final long serialVersionUID = 1L;

	private List<CartaIP> listaDeCartas = new ArrayList<CartaIP>();
	private long nextCartaID = 1;

    public BaralhoIP() {
    	super();
    }

	public CartaIP addCarta() {
		CartaIP newCarta = new CartaIP(nextCartaID++);
		this.listaDeCartas.add(newCarta);
		return newCarta;
	}

	public CartaIP getCarta(long ID) {
		for (Iterator<CartaIP> i = listaDeCartas.iterator(); i.hasNext(); ) {
			CartaIP currentCarta = (CartaIP) i.next();
			if (currentCarta.getID() == ID) 
				return currentCarta;
		}
		return null;
	}

	public boolean removeCarta(long ID) {
		for (Iterator<CartaIP> i = listaDeCartas.iterator(); i.hasNext(); ) {
			CartaIP currentCarta = (CartaIP) i.next();
			if (currentCarta.getID() == ID) { 
				i.remove(); 
				return true; 
			} 
		}
		return false;
	}

	public long getSize() {
		return listaDeCartas.size();
	}
}